﻿/*
文件名排序 
Time Limit:1000MS  Memory Limit:32768K

  
Description:
假如你打开一个文件夹发现里面的文件顺序是混乱的. 通常你会让操作系统对文件进行排序,否则看起来实在太不舒服了.
但是这究竟是怎样一个过程呢? 
	
Input:
输入共n行(0<n<=10000) 每行包含数据Ni,Ai,用空格分隔其中Ni为文件名(无空格),Ai为属性("File"代表文件,"Dir"代表文件夹) 
Output:
输出排序后的结果 
Sample Input:
msvcrt40.dll File
cliconfg.dll File
drivers Dir
rasman.dll File
setver.exe File

Sample Output:
drivers Dir
cliconfg.dll File
msvcrt40.dll File
rasman.dll File
setver.exe File
Hint:
文件名比较时忽略大小写, 文件夹总是排在文件的前面. 
*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
using namespace std;

class FileInfo
{
private:
	string _name;
	bool _isFile;
public:

	FileInfo(string name="", bool isFile=true):
	  _name(name), _isFile(isFile)
	  {

	  }
	friend istream& operator>> (istream& is, FileInfo& fileInfo)
	{
		string attribute;
		is>>fileInfo._name>>attribute;

		if(0==attribute.length() || string::npos==attribute.find("File"))
			fileInfo._isFile=false;
		else
			fileInfo._isFile=true;
		return is;
	}

	friend ostream& operator<< (ostream& os, const FileInfo& fileInfo) 
	{
		os<<fileInfo._name<<" "<<(fileInfo._isFile?"File":"Dir");
		return os;
	}

	friend bool compare(const FileInfo& fi1, const FileInfo& fi2)
	{
		if (fi1._isFile==fi2._isFile)
		{
			string name1(fi1._name), name2(fi2._name);
			transform(name1.begin(), name1.end(), name1.begin(), towlower);
			transform(name2.begin(), name2.end(), name2.begin(), towlower);
			return name1<name2;
		}
		else if(fi1._isFile)
			return false;
		return true;
	}
};


int main(int argc, char* argv[])
{
	vector<FileInfo> vfi;
	vfi.reserve(100);
	
	for (FileInfo fileInfo;cin>>fileInfo;)
	{
		vfi.push_back(fileInfo);
	}
	sort(vfi.begin(), vfi.end(), compare);
	copy(vfi.begin(), vfi.end(), ostream_iterator<FileInfo>(cout, "\n"));

	return 0;
}

